home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Languages / Masm V6.11 / LIB / APPENTRY.AS$ / APPENTRY
Encoding:
Text File  |  1992-09-08  |  3.8 KB  |  110 lines

  1. ;-----------------------------------------------------------------------------;
  2. ; APPENTRY.ASM :Windows Application Startup Routine
  3. ;-----------------------------------------------------------------------------;
  4. ; From Microsoft Windows Software Developers Kit (c) Microsoft
  5. ; Chapter 22: Windows Application Startup
  6. ;-----------------------------------------------------------------------------;
  7. ;
  8. ; To create a Windows application, the WinMain function has to be called
  9. ; by some startup code contained in the executable file. This startup code is 
  10. ; in the APPENTRY.ASM file. Since INVOKE directives depend on the memory model
  11. ; in use, APPENTRY.ASM expects MODEL to be set with the memory model of
  12. ; the application. APPENTRY.OBJ is then created from APPENTRY.ASM.
  13. ;
  14. ; for example:    ml -c -DMODEL=small appentry.asm
  15. ; In the link line, APPENTRY.OBJ has to be the first file in the chain,
  16. ; because the first 16 bytes of data in the DATA segment are reserved by 
  17. ; Windows. A run file name has to be specified to the linker, otherwise
  18. ; the linker will create an APPENTRY.EXE executable.
  19. ;
  20. ; for example:    link  appentry+winapp,winapp.exe,,libw,winapp
  21. ;
  22. ; For PWB, this amounts to selecting APPENTRY.ASM as the first entry in the
  23. ; list (put APPENTRY.ASM at the Top of List)
  24. ; Since MODEL is required, an IFNDEF handles the case in which it isn't
  25. ; defined, outputting an error and avoiding assembly of the rest.
  26. ;
  27. ;-----------------------------------------------------------------------------;
  28.  
  29.  
  30. IFNDEF MODEL
  31.     .ERR <MODEL hasn't been defined>
  32.     EXTERNDEF  __astart:PROC
  33. ELSE
  34.     .model MODEL, pascal            ; set model to MODEL, language
  35.                     ; to pascal (as required by Windows)
  36.                     ; MODEL should be defined in ML
  37.                     ; command line
  38.  
  39. ; Numeric Equates
  40.  
  41. STACKSLOP = 256                         ; amount of stack slop space required
  42. maxRsrvPtrs = 5                         ; number of Windows reserved pointers
  43.  
  44. ; External/Public definitions
  45.  
  46. EXTERNDEF       rsrvptrs:WORD           ; pointers to Windows reserved pointers
  47. PUBLIC          __astart                ; application startup routine
  48.  
  49. ; Type definitions for functions used. 
  50. ; Faster and more efficient than including 'windows.inc'
  51.  
  52. UINT            TYPEDEF WORD
  53. HINSTANCE       TYPEDEF UINT
  54. HTASK           TYPEDEF UINT
  55. LPSTR           TYPEDEF FAR PTR BYTE
  56.  
  57.  
  58. ; Prototypes for functions used
  59.  
  60. Dos3Call        PROTO FAR PASCAL
  61. InitApp         PROTO FAR PASCAL,       :HTASK
  62. WaitEvent       PROTO FAR PASCAL,       :HINSTANCE
  63. InitTask        PROTO FAR PASCAL
  64. WinMain         PROTO NEAR PASCAL,      :HINSTANCE, :HINSTANCE, :LPSTR, :UINT
  65.  
  66.     .data
  67.  
  68.      DWORD  0                       ; Windows reserved data space.
  69. rsrvptrs WORD   maxRsrvPtrs             ; 16 bytes at the top of the DATA seg.
  70.      WORD   maxRsrvPtrs DUP (0)     ; Do not alter
  71.  
  72. hPrev    WORD    0                      ; space to save WinMain parameters
  73. hInst    WORD    0
  74. lpszCmd  DWORD   0
  75. cmdShow  WORD    0
  76.  
  77.     .code
  78.  
  79. __astart:
  80.     xor bp,bp                       ; zero bp
  81.     push bp
  82.     INVOKE InitTask                 ; Initialize the stack
  83.     or ax,ax
  84.     jz noinit
  85.     add cx,STACKSLOP                ; Add in stack slop space.
  86.     jc noinit                       ; If overflow, return error.
  87.     mov hPrev,si
  88.     mov hInst,di
  89.     mov word ptr lpszCmd,bx
  90.     mov word ptr lpszCmd+2,es
  91.     mov cmdShow,dx
  92.     xor ax,ax                       ; Clear initial event that
  93.     INVOKE WaitEvent, ax            ;   started this task.
  94.     INVOKE InitApp, hInst           ; Initialize the queue.
  95.     or ax,ax
  96.     jz noinit
  97.  
  98.     INVOKE WinMain, hInst,hPrev,lpszCmd,cmdShow
  99. ix:
  100.     mov ah,4Ch
  101.     INVOKE Dos3Call                 ; Exit with return code from app.
  102. noinit:
  103.     mov al,0FFh                     ; Exit with error code.
  104.     jmp short ix
  105.     
  106. ENDIF                                   ; End of IFNDEF MODEL
  107.  
  108.     end __astart                    ; start address
  109.